<?
require_once("classes.php");
if ((isset($_SESSION['permissao']))and ($_SESSION['permissao']==1)) {
if ((!session_is_registered("login")) or ($_SESSION['valida']<>"asd0jsdfji07ij@-0_djf-657asd"))
{$ok = false;
}else{$ok = true; 
$atual = $_POST['atual'];
$nova = $_POST['nova'];
if ($atual!="" and $nova!=""){ 
	require_once('conexao.php');
	$sql = "SELECT * FROM USUARIO WHERE APELIDO = '".$_SESSION['login']."' and SENHA = '".$atual."' and HABILITADO='TRUE';"; 
	if (!$resultado = pg_query($conexao, $sql)) {
	printf("Error: %s\n", pg_result_error($resultado));
	}
	if (pg_num_rows($resultado)>0){
				$sql = "UPDATE USUARIO SET SENHA = '".$nova."' WHERE APELIDO = '".$_SESSION['login']."' and SENHA = '".$atual."' and HABILITADO='TRUE';"; 
				if (!$resultado = pg_query($conexao, $sql)) {
				printf("Error: %s\n", pg_result_error($resultado));
				}else{
				$msg = "Senha alterada com sucesso!";
				}
		}else{
		$msg ="Senha atual incorreta!";
		}@pg_result_error($resultado);	
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/webcosts.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<SCRIPT language=JavaScript src="menu.js"></SCRIPT>
<!-- InstanceBeginEditable name="doctitle" -->
<title>:.WebCosts .: Sistema ...</title>
<script language="JavaScript" type="text/javascript">
 function setFocus(){document.frm.atual.focus();}
</script>
<? $onLoad="";
if ($ok == false){$onLoad="setFocus()";}?>
<link rel="stylesheet" href="../estilos/estilo.css" type="text/css" />
<!-- InstanceEndEditable -->
</head>
<body onLoad="<?=$onLoad?>">
<div id=tudo>
	<div id=topo>
    <H1><B class=destaque>WebCosts</B> - Controle de Custos</H1>
  </div>
  <div id=nav>
	<? if ($ok == true)@require("../menu.php");?>
	</div>
	<div id=principal>
	<!-- InstanceBeginEditable name="conteudo" -->
	 <P>&nbsp;</P>
		<div id=apoio class=fixo>
		<div align="left">
			
					<form name="frm" method="post" action="altera_senha.php">
					 <B class=destaque>Senha Atual:</B>
					 <input name="atual" type="password" size="12"><br>
					 <B class=destaque>Nova Senha:</B>
					 <input name="nova" type="password" size="12">
					 <input type="submit" name="Submit" value=">>">
					</form>
		  <? echo $msg;?>
		   </div>
		</div>
	<P>&nbsp;</P>
	<!-- InstanceEndEditable -->
	</div>
	<div id=rodape>
	<P><B class=destaque>WebCosts.: </B>Implementa&ccedil;&atilde;o Grupo Porreta II.</P>
  </div>
</div>
</body>
<!-- InstanceEnd --></html>
<? 	} else header("Location: ../aviso.php");// permissao
?>